package com.ruiya.staging.goods.cas.util;

import com.ruiya.staging.goods.core.constants.ErrorCodeEnum;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

public class ResponseUtils {

    public static Pair<String, String> getParamVerifyError(BindingResult result){
        if (result.hasErrors()) {
            List<ObjectError> list = result.getAllErrors();
            for (ObjectError error : list) {
                return new ImmutablePair<>(ErrorCodeEnum.PARAMSERROR.getCode(), error.getDefaultMessage());
            }
        }
        return new ImmutablePair<>(ErrorCodeEnum.PARAMSERROR.getCode(), ErrorCodeEnum.PARAMSERROR.getMsg());
    }

}
